<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class ContentController extends Controller{


    //动作
    public function index(){
       if(IS_POST){
//     	var_dump($_POST);die;
			
		   $pData=$_POST;

		   $goodsModel=new \Common\Model\Goods;
		   $goodsData=$goodsModel->where('gid',$pData['gid'])->find();
		   
		   $gaModel=new \Common\Model\Goods_attr;
		   $color=$gaModel->where('gaid',$pData['color'])->pluck('ganame');
		   $size=$gaModel->where('gaid',$pData['size'])->pluck('ganame');
		   $shopData=array();
		   $shopData=array(
		   		'id'=>$pData['gid'],
		   		'name'=>$goodsData['gname'],		   		
		   		'num'=>$pData['num'],
		   		'price'=>$goodsData['shopprice'],
		   		'options'=>array(
		   			'pic'=>$goodsData['pic'],
		   			'combine'=>$pData['combine']
				),
		   		'color'=>$color,
		   		'size'=>$size,
		   );
//			p($shopData);die;
			
			Cart::add($shopData); // 添加到购物车 
//			p($_SESSION); die;
//			View::success('添加成功',U('index'));
       }

		$gid=Q('get.gid',0,'intval');
		$shoeData=Db::table('goods g')
		->join('goods_attr ga','g.gid','=','ga.goods_gid' )
		->join('type_attr ta','ga.type_attr_taid','=','ta.taid' )
		->join('goods_detail gd','g.gid','=','gd.goods_gid' )
		->where('gid',$gid)
		->where('class',1)
		->groupBy('taname')
		->orderBy('taid','ASC')
		->get();
		
		foreach($shoeData as $k=>$v){
			$shoeData[$k]['sonData']=
			Db::table('goods_attr ga')
		->join('type_attr ta','ga.type_attr_taid','=','ta.taid')
		->where('ta.class',1)
		->where('ga.goods_gid',$gid)
		->where('ta.taid',$v['taid'])
		->orderBy('gaid','ASC')
		->get();
		}
		
		$shoeData[0]['photo']=explode(',',$shoeData[0]['photo']);
//		p($shoeData);die;	   

		View::with('shoeData',$shoeData);
		
		$shoeAttrData=Db::table('goods g')
		->join('goods_attr ga','g.gid','=','ga.goods_gid' )
		->join('type_attr ta','ga.type_attr_taid','=','ta.taid' )
		->join('goods_detail gd','g.gid','=','gd.goods_gid' )
		->where('gid',$gid)
		->where('class',0)
		->groupBy('taname')
		->orderBy('taid','ASC')
		->get();
		
//		p($shoeAttrData);die;
		View::with('shoeAttrData',$shoeAttrData);	   
		
		$brandModel=new \Common\Model\Brand;
		$brand=$brandModel->where('bid',$shoeData[0]['brand_bid'])->pluck('bname');
		View::with('brand',$brand);
	    View::make();
    }
	
	
		public function getCombine(){
//		echo 'ok';die;
		$gid=Q('get.gid',0,'intval');
//		var_dump($gid);die;
		$combine=$_POST['combine'];
		$goods_listModel=new \Common\Model\Goods_list;
//		var_dump($combine);die;
		$inventory=$goods_listModel->where('combine',$combine)->where('goods_gid',$gid)->pluck('inventory');
		
		
		View::ajax($inventory);die;
	}
	
	
	
}
